

;; Load in DPDFs
conf  = omni_load_conf()
dpdfs = omni_read_conffile('./conffiles/dpdf_params.conf') 
mw    = omni_read_conffile('./conffiles/galactic_params.conf')

message,conf.survey,/inf

IF ~exist(pvec) THEN $
   restore,'./local/'+conf.survey+'_pvec.sav',/ver

ind = where(constrain.post, n)
print,n

p = pvec[ind]
c = constrain[ind]

help,p.stat,/str

dsun = p.stat.duse[0]
iig = where(p.glon LE 90.)
iog = where(p.glon GT 90.)

omni_lbd2rz,p.glon,p.glat,dsun,rgal,zgal


;;======================================================
;; The PLOT!
myps,'./grs_paper/zfa.eps',xsize=2.1,ysize=2.0,thick=1.5
!x.omargin = [+1.3,-0.95]
!y.omargin = [-0.0,-1.3]
multiplot,[1,1]

csf = 0.55

;; Panel 1: Z distribution
print,m4_stat(zgal)

plothist,zgal,bin=5,charsize=1.0*csf,xtit='z!dgal!n  [pc]',$
         ytit='N per 5 pc bin',yr=[0,170],$
         xarr,yarr,xr=[-150,200],/fill,fcolor='skyblue',color='cyan'
         
yft = mpfitpeak(xarr,yarr,A,nterms=3,ERROR=sqrt(float(yarr)),PERROR=perr,$
               CHISQ=chisq,DOF=dof)
print,'Z Gaussian fit: ',chisq,dof,chisq/dof
cgOplot,xarr,yft,color='black'

cgAxis,xaxis=0,xtickformat='blank_axis',/xst

al_legend,/top,/left,box=0,charsize=0.9*csf,$
          ['Fit Centroid = '+string(A[1],format="(F+0.1)")+' '+cgsymbol('+-')+$
          ' '+string(perr[1],format="(F0.1)")+' pc',$
          'FWHM = '+string(A[2]*2.355,format="(F0.1)")+' '+cgsymbol('+-')+$
          ' '+string(perr[2]*2.355,format="(F0.1)")+' pc']

al_legend,/top,/right,box=0,['N = '+string(n_elements(zgal),format="(I0)")],$
          charsize=0.9*csf

myps,/done,/mp
myps,'./grs_paper/zfb.eps',xsize=2.1,ysize=2.0,thick=1.5
multiplot,[1,1]

;; Panel 2: z vs \dsun
cgPlot,dsun/1.d3,zgal,charsize=1.0*csf,psym=16,symsize=0.4,$
       ytit='z!dgal!n  [pc]',$
       xtit='Heliocentric Distance  [kpc]',/nodata,yr=[-150,200]
vline,/h,+60,color='blk5',linestyle=4
vline,/h,-60,color='blk5',linestyle=4

d = findgen(dpdfs.nbins)*dpdfs.binsize + dpdfs.binstart
omni_lbd2rz,30.,+0.5,d,rj,ztop
omni_lbd2rz,30.,-0.5,d,rj,zbot
cgOplot,d/1.d3,ztop,color='cyan',linestyle=2
cgOplot,d/1.d3,zbot,color='cyan',linestyle=2

cgOplot,dsun[iig]/1.d3,zgal[iig],psym=16,symsize=0.2
cgOplot,dsun[iog]/1.d3,zgal[iog],psym=16,symsize=0.2,color='red'


myps,/done,/mp
myps,'./grs_paper/zfc.eps',xsize=2.1,ysize=2.0,thick=1.5
multiplot,[1,1]

;; Panel 3: z vs. R_gal
cgPlot,rgal/1.d3,zgal,charsize=1.0*csf,psym=16,symsize=0.4,$
       ytit='z!dgal!n  [pc]',$
       xtit='Galactocentric Radius  [kpc]',/nodata,yr=[-150,200]
vline,/h,+60,color='blk5',linestyle=4
vline,/h,-60,color='blk5',linestyle=4

cgPlots,mw.r0/1.d3,mw.z0,psym='filledstar',color='orange',symsize=1.0
cgPlots,mw.r0/1.d3,mw.z0,psym='star',color='black',symsize=1.0,thick=1


cgOplot,rgal[iig]/1.d3,zgal[iig],psym=16,symsize=0.2
cgOplot,rgal[iog]/1.d3,zgal[iog],psym=16,symsize=0.2,color='red'



myps,/done,/mp



END
